/**
 * 
 */
package cn.agiledata.bank.facade.helper;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import org.springframework.ui.velocity.VelocityEngineUtils;

import cn.agiledata.bank.common.exception.BusinessException;

/**
 * 模板助手，使用Velocity
 * 
 * @author 马贤波
 *
 * 2006-7-10
 */
public class TemplateHelper{
	
	private static Log log = LogFactory.getLog(TemplateHelper.class);
	private static final String PREFIX = "templates/" ;
	
	private  VelocityEngine velocityEngine ;
	
	public String mergeContent(String templateName,  Map context) {
		String result = "";
		templateName = PREFIX + templateName ;
	    try {
	        result = VelocityEngineUtils.mergeTemplateIntoString(
	        		this.velocityEngine, templateName, context);
	    } catch (VelocityException e) {
	    	e.printStackTrace() ;
	    	log.error(e) ;
	        throw BusinessException.INFRA_FAILURE;
	    }
	    
	    return result ;
	}

	public VelocityEngine getVelocityEngine() {
		return velocityEngine;
	}



	public void setVelocityEngine(VelocityEngine velocityEngine) {
		this.velocityEngine = velocityEngine;
	}
	
}
